package com.infoblazer.jimql;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * User: Dave
 * Date: Nov 18, 2010
 * Time: 10:31:10 PM
 *
 */
public class H2Jimql implements JimqlConnection {
     public Connection buildConnection(ThreadLocal<Connection> connectionThreadLocal){
           Connection conn = null;
        try {
             Class.forName("org.h2.Driver");
              conn = DriverManager.getConnection("jdbc:h2:mem:jimql ");
            
        } catch (SQLException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        } catch (ClassNotFoundException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
           return conn;
    }

   public void dropIfExists(Connection conn ,String tableName) throws SQLException {
         Statement st = null;
         try {
            st = conn.createStatement();
            StringBuilder sb = new StringBuilder();
            sb.append("DROP TABLE ").append(tableName);
            st.execute(sb.toString());
            }
         catch (SQLException ok) {

            }
        finally {
             st.close();
         }
    }
}
